package com.juku2024.juku.dialog

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.widget.Button
import android.widget.TextView
import com.juku2024.juku.R
import com.juku2024.juku.callback.OnNoDoubleClickListener
import com.juku2024.juku.tools.AppUtils
import com.juku2024.juku.tools.DisplayUtil

class DownloadRewardAdDialog(context: Context, style: Int = R.style.CommonDialogStyle) : Dialog(context, style){

    private lateinit var btnCancel: Button
    private lateinit var btnConfirm: Button
    private lateinit var tv: TextView
    private lateinit var tvDialogMsg: TextView
    private lateinit var tvDialogTitle: TextView
    var onShowAdListener: OnNoDoubleClickListener? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.dialog_download_reward_ad)

        btnCancel = findViewById(R.id.btn_cancel_download_reward_ad)
        btnConfirm = findViewById(R.id.btn_confirm_download_reward_ad)
        tv = findViewById(R.id.tv_download_reward_ad)
        tvDialogMsg = findViewById(R.id.tv_dialog_msg_download_reward_ad)
        tvDialogTitle = findViewById(R.id.tv_dialog_title_download_reward_ad)

        setCanceledOnTouchOutside(false) //点击边际可消失
        setCancelable(false)
        btnCancel.setOnClickListener {
            dismiss()
            val activity = AppUtils.findActivity(context)
            activity?.finish()
        }

        btnConfirm.setOnClickListener(object: OnNoDoubleClickListener{
            override fun onNoDoubleClick(v: View?) {
                super.onNoDoubleClick(v)
                onShowAdListener?.onNoDoubleClick(v)
            }
        })
    }

    override fun onStart() {
        super.onStart()
        val dialogHeight = DisplayUtil.dp2px(context, 180f)
        val dialogWight = DisplayUtil.dp2px(context, 300f)
        window?.setLayout(dialogWight, dialogHeight)
    }

    fun setData(title: String, msg: String, btn: String) {
        tvDialogTitle.text = title
        tvDialogMsg.text = msg
        tv.text = btn
    }

}